package com.at.bigdata.spark.streaming

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext, StreamingContextState}

/**
 *
 * @author cdhuangchao3
 * @date 2023/5/29 9:24 PM
 */
object SparkStreaming09_Resume {

  def main(args: Array[String]): Unit = {
    val ssc = StreamingContext.getActiveOrCreate("cp", () => {
      val sc = new SparkConf().setMaster("local[*]").setAppName("operator")
      new StreamingContext(sc, Seconds(3))
    })
    ssc.checkpoint("cp")

    val lines = ssc.socketTextStream("localhost", 9999)
    val word2One = lines.map((_, 1))
    word2One.print()

    ssc.start()
    ssc.awaitTermination() // 阻塞main线程

  }

}
